package com.github.wisdom.common.github.modules.fegin.fallback;

import feign.Response;
import feign.Util;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;

@Configuration
public class CommonFeignErrorDecoder implements ErrorDecoder {
    @Override
    public Exception decode(String methodKey, Response response) {
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        try {
            String message = Util.toString(response.body().asReader());
            Exception e=new RuntimeException(message);
            e.printStackTrace();
            return e;
        } catch (IOException ignored) {
        }
        return decode(methodKey, response);
    }
}
